home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 892 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  1.4 KB

  1. Path: news.rmii.com!usenet
  2. From: bmeardon@rmii.com (Brandon Meardon)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Help with cin.get()
  5. Date: Mon, 08 Jan 1996 06:45:10 GMT
  6. Organization: Rocky Mountain Internet Inc.
  7. Message-ID: <4cqebj$oje@natasha.rmii.com>
  8. References: <4cqbja$62n@earth.njcc.com>
  9. NNTP-Posting-Host: slip858.rmii.com
  10. X-Newsreader: Forte Free Agent 1.0.82
  11.  
  12. chris@pluto.njcc.com (Chris Conway) wrote:
  13.  
  14. >I use this function to input a book title with imbedded blanks:
  15.  
  16. >    void getdata()
  17. >       {
  18. >       cout << "Enter title: ";
  19. >       cin.get(title, LEN);
  20. >       cout << "Enter price: ";
  21. >       cin >> price;
  22. >       }
  23.  
  24. >problem is, if I execute the function more than once, it skips the title input 
  25. >on the second and every subsequent execution (i.e. the line will resemble:
  26. >     Enter title: Enter price: 
  27. >never offering the oppurtunity to enter the title).
  28.  
  29. >I suspect this little "bug" arises from a subtle misuse of cin.get().  Can 
  30. >anyone identify it for me?  This is obviously a beginner question.
  31.  
  32. >My thanks and apologies.
  33. >chris.
  34. >chris@pluto.njcc.com
  35.  
  36.  
  37. This is not just a problem with the cin.get method but also when you
  38. stream the input in useing the >> operator.  What I think is happening
  39. here is that the buffer is not getting properly flushed, you might
  40. want to look in the reference book to see how you can manualy flush
  41. the cin buffer.
  42.  
  43. good luck,
  44.  
  45. Brandon
  46.  
  47.  
  48.